package com.topisv.tms.repository.lpn;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.topisv.tms.costants.StorageConstants;
import com.topisv.tms.entity.lpn.LPN;

public interface LPNDao extends PagingAndSortingRepository<LPN, Long>, JpaSpecificationExecutor<LPN> {
    
    @Query("select t from LPN t  where t.warehouseCode=?1 and t.lpnNo=?2 and t.status<>'2'  ")
    LPN loadLPN(String warehouseCode, String lpnNo);
    
    @Query("select t from LPN t  where t.warehouseCode=?1 and t.lpnNo=?2   ")
    List<LPN> checkLPN(String warehouseCode, String lpnNo);
    
    @Query("select t from LPN t  where t.warehouseCode=?1 and t.storageType=?2 and t.status='0'  order by id  ")
    List<LPN> loadFreeLPN(String warehouseCode, String type);
    
    @Modifying
    @Query("UPDATE LPN SET status = ?2,storageTable=?3 WHERE id=?1  ")
    int updateLpnById(long id, String status, String table);
    
    @Query("select t from LPN t  where t.warehouseCode=?1   ")
    List<LPN> loadLPNNum(String warehouseCode);
    
    @Query("select count(t.id) from LPN t  where t.warehouseCode=?1 and t.storageType=?2 and t.status="
        + StorageConstants.LPN_STATUS_FREE)
    Long countFreeLpn(String warehouseCode, String type);
    
    @Query("select t from LPN t where t.warehouseCode=?1 and t.flag = ?2 ")
    List<LPN> getLpnByFlag(String warehouseCode, String updFlag);
    
    @Query("select t from LPN t  where  t.lpnNo=? and t.status<>'2'  ")
	LPN loadByLpnNo(String lpn);
    
}
